namespace SimpleWebServices.Web
{
    using System.Web;
    using System.Xml.Serialization;
    using SimpleWebServices.Data;
    using SimpleWebServices.Web.UI.Html;

    [XmlRoot("resource")]
    public abstract class Resource : Record, IResource
    {
        protected Resource()
            : base(HttpCacheability.Public)
        {
            this.Data = new DataCollection();
            this.Links = new LinkCollection();
            this.Metadata = new MetaCollection();
        }

        [XmlElement("data")]
        public DataCollection Data
        {
            get;
            set;
        }

        [XmlAttribute("description")]
        public string Description
        {
            get;
            set;
        }

        [XmlIgnore]
        public override string Entity
        {
            get
            {
                Entity value = new Entity();
                value.Append(this.Data);
                value.Append(this.Description);
                value.Append(this.Links);
                value.Append(this.LocationString);
                value.Append(this.Metadata);
                value.Append(this.Title);

                return value;
            }
        }

        [XmlElement("links")]
        public LinkCollection Links
        {
            get;
            set;
        }

        [XmlIgnore]
        public RelativeUri Location
        {
            get
            {
                return this.LocationString;
            }

            set
            {
                this.LocationString = value;
            }
        }

        [XmlAttribute("location")]
        public string LocationString
        {
            get;
            set;
        }

        [XmlElement("metadata")]
        public MetaCollection Metadata
        {
            get;
            set;
        }

        [XmlAttribute("title")]
        public string Title
        {
            get;
            set;
        }
    }
}